//
//  YDViewController.m
//  YDOCBarrage
//
//  Created by Arthur on 12/05/2019.
//  Copyright (c) 2019 Arthur. All rights reserved.
//

#import "YDViewController.h"
#import "OCBarrage.h"

#import "YDBarrageWalkBannerCell.h"

#define kRandomColor [UIColor colorWithRed:arc4random_uniform(256.0)/255.0 green:arc4random_uniform(256.0)/255.0 blue:arc4random_uniform(256.0)/255.0 alpha:1.0]

@interface YDViewController ()

@property (nonatomic, strong) OCBarrageManager *barrageManager;

@end

@implementation YDViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    self.barrageManager = [[OCBarrageManager alloc] init];
        [self.view addSubview:self.barrageManager.renderView];
    self.barrageManager.renderView.frame = CGRectMake(0.0, [UIApplication sharedApplication].statusBarFrame.size.height+82, self.view.frame.size.width, 300);
    self.barrageManager.renderView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self startBarrage];
}

- (void)startBarrage {
    [self.barrageManager start];
}

- (void)addWalkBannerBarrage {
    YDBarrageWalkBannerDescriptor *bannerDescriptor = [[YDBarrageWalkBannerDescriptor alloc] init];
    bannerDescriptor.cellTouchedAction = ^(OCBarrageDescriptor *__weak descriptor, OCBarrageCell *__weak cell) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"OCBarrage" message:@"全民超人为您服务" delegate:nil cancelButtonTitle:@"朕知道了" otherButtonTitles:nil];
        [alertView show];
        
        YDBarrageWalkBannerCell *walkBannerCell = (YDBarrageWalkBannerCell *)cell;
        walkBannerCell.textLabel.backgroundColor = [UIColor redColor];
    };
    
    bannerDescriptor.bannerLeftImageSrc = @"你是最漂亮的";
    bannerDescriptor.text = [NSString stringWithFormat:@"你是最棒的，棒棒棒棒"];
    bannerDescriptor.textColor = UIColor.whiteColor;
    bannerDescriptor.textFont = [UIFont systemFontOfSize:13.0];
    bannerDescriptor.positionPriority = OCBarragePositionMiddle;
    bannerDescriptor.strokeColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    bannerDescriptor.strokeWidth = -1;
    bannerDescriptor.animationDuration = arc4random()%5 + 5;
    bannerDescriptor.barrageCellClass = [YDBarrageWalkBannerCell class];
    [self.barrageManager renderBarrageDescriptor:bannerDescriptor];
    
    
}

// MARK: 生成一个弹幕
- (IBAction)addBarrage:(UIButton *)sender {


    [self addWalkBannerBarrage];



}

- (IBAction)click:(UIButton *)sender {
    
    
    NSLog(@"测试是否穿透");
}




- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
